package com.zyh.scs.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyh.scs.admin.api.dto.RechargeBatchJsonDTO;
import com.zyh.scs.admin.api.dto.RechargePageDTO;
import com.zyh.scs.admin.api.dto.RechargePhoneDTO;
import com.zyh.scs.admin.service.UserRechargeService;
import com.zyh.scs.common.core.util.R;
import com.zyh.scs.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author hwh
 * @ClassName: 用户充值 访问$
 * @Description: $
 * @Date $
 * @Version 1.0
 */
@RestController
@AllArgsConstructor
@RequestMapping("/recharge")
@Tag(description = "recharge", name = "用户充值模块")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class UserRechargeController {

    private final UserRechargeService userRechargeService;

    /**
     * 分页查询用户充值列表
     *
     * @param page 参数集
     * @return 用户集合
     */
    @GetMapping("/page")
    @Operation(summary = "分页查询用户 账户列表", description = "分页查询用户充值列表")
    @PreAuthorize("@pms.hasPermission('scsx_recharge_view')")
    public R getUserPage(@ParameterObject Page page) {
        return R.ok(userRechargeService.getUserPage(page));
    }

    /**
     * 分页查询用户充值记录列表
     *
     * @param page 参数集
     * @return 用户集合
     */
    @GetMapping("/getUserRecordPage")
    @Operation(summary = "分页查询用户充值记录列表", description = "分页查询用户充值记录列表")
    @PreAuthorize("@pms.hasPermission('scsx_recharge_record_view')")
    public R getUserRecordPage(@ParameterObject Page page, RechargePageDTO rechargePageDTO) {
        return R.ok(userRechargeService.getUserRecordPage(page, rechargePageDTO));
    }


    /**
     * 通过用户id,手机号,工号查询用户
     *
     * @param param 参数集
     * @return 通过用户id, 手机号, 工号查询用户
     */
    @PreAuthorize("@pms.hasPermission('sys_user_view')")
    @GetMapping("/getRechargePhone")
    @Operation(summary = "通过用户id,手机号,工号查询用户", description = "通过用户id,手机号,工号查询用户")
    public R getRechargePhone(String param) {
        return R.ok(userRechargeService.getRechargePhone(param));
    }


    /**
     * 单个充值
     *
     * @param rechargePhoneDTO 参数集
     * @return 通过用户id, 手机号, 工号查询用户
     */
    @PostMapping("/recharge")
    @Operation(summary = "单个充值", description = "单个充值")
    @PreAuthorize("@pms.hasPermission('scsx_recharge_record_add')")
    public R recharge(@Valid @RequestBody RechargePhoneDTO rechargePhoneDTO) {
        return R.ok(userRechargeService.recharge(rechargePhoneDTO));
    }


    /**
     * 批量充值解析文件
     *
     * @param multipartFile 参数集
     * @return 结果集
     */
    @PostMapping("/read")
    @Operation(summary = "批量充值解析文件", description = "批量充值解析文件")
    @PreAuthorize("@pms.hasPermission('scsx_recharge_record_view')")
    public R read(MultipartFile multipartFile) {
        return R.ok(userRechargeService.read(multipartFile));
    }


    /**
     * 批量充值
     *
     * @return 批量充值
     */
    @PostMapping("/page")
    @Operation(summary = "批量充值", description = "批量充值")
    @PreAuthorize("@pms.hasPermission('scsx_recharge_record_add')")
    public R rechargeBatch(@RequestBody RechargeBatchJsonDTO rechargeBatchJsonList) {
        return R.ok(userRechargeService.rechargeBatch(rechargeBatchJsonList));
    }

    /**
     * 批量充值
     *
     * @return 批量充值
     */
    @PostMapping("/getIdFile")
    @Operation(summary = "批量充值 通过id 和文件", description = "批量充值 通过id 和文件")
    @PreAuthorize("@pms.hasPermission('scsx_recharge_record_add')")
    public R getIdFile(MultipartFile multipartFile, Long historyId, String fileName) {
        return R.ok(userRechargeService.getIdFile(multipartFile, historyId, fileName));
    }

    /**
     * 导出充值表头
     */
    @GetMapping("/export")
    @Operation(summary = "导出充值表头", description = "导出充值表头")
    public R export() {
        return R.ok(userRechargeService.getExcel());
    }

    /**
     * 充值记录流水导出Excel
     *
     * @return 用户集合
     */
    @GetMapping("/getUserRecordExport")
    @ResponseExcel
    @Operation(summary = "充值记录流水导出Excel", description = "充值记录流水导出Excel")
    public List getUserRecordExport(RechargePageDTO rechargePageDTO) {
        return userRechargeService.getUserRecordExport(rechargePageDTO);
    }

}
